package com.itheima.dao;

import com.itheima.domain.Person;


import java.util.ArrayList;

public class OtherPersonDao {
    private  static ArrayList<Person> a = new ArrayList<>();
    static {

        Person p = new Person("12321","12321","12321","12321");
        a.add(p);
    }
    public boolean add(Person s) {
        a.add(s);
        return true;
    }

    public Person[] select() {
        Person [] p = null;
        try{
             p = new Person[a.size()];
            for (int i = 0; i < p.length; i++) {
                p[i]=a.get(i);
            }
        }catch (Exception e ){
//            System.out.println("无信息，请添加！");
//            e.fillInStackTrace();
//
        }

        return p;
    }
    public int isExist(String nextSid) {
        Person [] select = select();
        int index = -1;
        for (int i = 0; i < select.length; i++) {
            try{
                if(nextSid.equals(select[i].getSid())){
                    index++;
                }
            }catch (Exception e){
                e.fillInStackTrace();
            }
        }
        return index;
    }

    public void delete(int index) {
        a.remove(index);
    }
}
